package com.motionlog.activity;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;

import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.motionlog.R;

public class SettingPassword extends Activity implements OnClickListener {

	private static final String TAG = SelectReason.class.getSimpleName();

    private Button bt1 = null,bt2 = null;
 
    private EditText  editText1,editText2;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setpassword);
       
        editText1 = (EditText)this.findViewById(R.id.editText1);
        editText1.setOnClickListener(this); 
        
        editText2 = (EditText)this.findViewById(R.id.editText2);
        editText2.setOnClickListener(this); 
        
        bt1 = (Button)this.findViewById(R.id.buttonSetp);
        bt1.setOnClickListener(this);    

       
       
        
    
       
                  
    }
    
    
  

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.buttonSetp:
		
			if(editText1.getText().toString().equals(editText2.getText().toString()))
			{
				SharedPreferences sets = getSharedPreferences("settings", MODE_PRIVATE);
				sets.edit().putBoolean("password", true).commit();
				sets.edit().putString("password-value", editText1.getText().toString()).commit();
				startHome();
			}
			else
			{
				Toast.makeText(this, "两次 输入的密码不一致！"
						, Toast.LENGTH_SHORT).show();
			}
			break;
		default:

			break;
		}
	}

	private void startHome() {
		SharedPreferences sets = getSharedPreferences("settings", MODE_PRIVATE);
		boolean hasTutor = sets.getBoolean("tutor", true);
		Class startActivity;
		if (hasTutor) {
			startActivity = Tutorial.class;
			sets.edit().putBoolean("tutor", false);//.apply(); ////gggggg
			sets.edit().commit();
		} else {
			startActivity = Home.class;
		}
		Intent i = new Intent(this, startActivity);
		startActivity(i);
		finish();
	}
}